<template>
  <div class="songbox">
    <div class="dropdown">
      <el-dropdown trigger="click" :placement="position" @command="toAll">
        <span class="el-dropdown-link">
          {{currentSpan=="全部"?currentSpan+'歌单':currentSpan}}
          <i
            class="el-icon-arrow-down el-icon--right"
          ></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <div>
            <h5>添加标签</h5>
          </div>
          <div class="line"></div>
          <el-dropdown-item class="allspan">全部歌单</el-dropdown-item>
          <el-dropdown-item>黄金糕</el-dropdown-item>
          <el-dropdown-item>狮子头</el-dropdown-item>
          <el-dropdown-item>螺蛳粉</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>

    <div class="hotspan">
      <div class="divider_box">
        <span>热门标签:</span>
        <el-divider direction="vertical" class="myline"></el-divider>
        <span v-for="(item, index) in hotlist" :key="index" @click="sendSpan(item.name)">
          {{item.name}}
          <el-divider direction="vertical" v-if="index!=(hotlist.length-1)"></el-divider>
        </span>
      </div>
    </div>
    <sheet-list class="slist" :sheetlist="sheetlist" :dafultpage="1"></sheet-list>
    <el-pagination
      layout="prev, pager, next"
      :page-count="11"
      :page-size="100"
      @current-change="update"
      :current-page="dafultpage"
    ></el-pagination>
  </div>
</template>

<script>
import { Loading } from 'element-ui'
import sheetList from 'components/sheet-list/sheet-list'

export default {
  name: 'nav-songsheet',
  created () {
    this.loadingInstance = Loading.service({
      lock: true,
      target: ".el-main",
      text: "Loding...",
      spinner: "el-icon-loading"
    })
    this.getHot()
    this.getHotDetail()
  },
  data () {
    return {
      position: "bottom-start",
      hotlist: [],
      sheetlist: [],
      offset: 0,
      span: "全部",
      dafultpage: 1
    }
  },
  methods: {
    toAll () {
      this.span = "全部"
      this.update()
    },
    sendSpan (s) {
      this.span = s
      this.dafultpage = 1
      this.update()
    },
    update (index) {
      let i = index ? index : 1
      this.dafultpage = i
      this.offset = 100 * (this.dafultpage - 1)
      let loadingInstance = Loading.service({
        lock: true,
        target: ".slist",
        text: "Loding...",
        spinner: "el-icon-loading"
      })
      this.$http
        .get(
          `/api/top/playlist?limit=100&offset=${this.offset}&order=hot&cat=${this.currentSpan}`
        )
        .then((res, err) => {
          if (err) {
            console.log(err.message)
          } else {
            this.sheetlist = res.data.playlists
            this.$nextTick(() => {
              loadingInstance.setText("success")
              loadingInstance.close()
            })
          }
        })
    },
    getHot () {
      this.$http.get("/api/playlist/hot").then((res, err) => {
        if (err) {
          console.log(err.message)
        } else {
          this.hotlist = res.data.tags
        }
      })
    },
    getHotDetail () {
      this.$http.get("/api/top/playlist?limit=100&order=hot").then((res, err) => {
        if (err) {
          console.log(err.message)
        } else {

          this.sheetlist = res.data.playlists
          this.$nextTick(() => {
            this.loadingInstance.setText("success")
            this.loadingInstance.close()
          })
        }
      })
    },
  },
  computed: {
    currentSpan () {
      return this.span
    }
  },
  components: {
    sheetList
  }
}
</script>

<style lang="scss" scoped>
.songbox {
  position: relative;
  width: 100%;
  height: 800px;
  left: 0;
}
.el-dropdown-link {
  cursor: pointer;
  color: #000;
  border: 1px solid rgba(#ddd, 0.6);
  font-size: 12px;
  display: block;
  width: 78px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 5px;
  .el-icon--right {
    margin: 0;
  }
  /* &代表当前父类名*/
  &:hover {
    background-color: #efefef;
  }
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-dropdown {
  left: -366px;
  margin-bottom: 10px;
}
.el-dropdown-menu__item:hover {
  background-color: rgba(#eeeeeb, 0.3) !important;
  color: #000 !important;
}
.el-dropdown-menu {
  width: 580px;
  height: 400px;
  h5 {
    font-weight: normal;
    margin: 0;
    margin-left: 20px;
    padding: 5px 0 15px;
  }
  .line {
    border-bottom: 1px solid #ccc;
    width: 100%;
    margin: 0 auto;
  }
  .allspan {
    height: 30px;
    margin: 10px 0px;
    text-align: center;
    line-height: 30px;
    border: 1px solid red;
    font-size: 12px;
  }
}
.hotspan {
  margin-bottom: 20px;
  .divider_box {
    font-size: 12px;
    text-align: left;
    padding-left: 5px;
    user-select: none;
    .el-divider--vertical {
      margin: 0 12px;
    }
    span {
      color: #777;
      cursor: pointer;
      &:hover {
        color: #000;
      }
    }
    .myline {
      margin: 0 5px;
      height: 0;
    }
  }
}
</style>
<style lang="scss">
.el-loading-spinner {
  top: 4%;
}

.el-pager li {
  color: rgba(#000, 0.5);
  font-size: 12px;
}

.el-pager li.active {
  color: #c20c0c;
  font-size: 10px;
  text-decoration: underline;
}
.el-pager li:hover {
  background-color: #eee;
  color: #000;
}
</style>